//
//  HTTravelCell.m
//  HeartTravel
//
//  Created by lanou on 15/10/31.
//  Copyright © 2015年 陈文杰. All rights reserved.
//

#import "HTTravelCell.h"
#import "UIImageView+WebCache.h"

@implementation HTTravelCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        _bgImageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 5, SCREEN_WIDTH - 20, 220)];
        _bgImageView.layer.cornerRadius = 20;
        _bgImageView.layer.masksToBounds = YES;
        [self.contentView addSubview:_bgImageView];
        
        _titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 20, SCREEN_WIDTH - 60, 30)];
        _titleLabel.textColor = [UIColor whiteColor];
        _titleLabel.font = [UIFont systemFontOfSize:20];
    
        [_bgImageView addSubview:_titleLabel];
        
//        _timeLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 60, SCREEN_WIDTH - 60, 20)];
//        _timeLabel.textColor = [UIColor whiteColor];
//        _timeLabel.font = [UIFont systemFontOfSize:15];
//        [_bgImageView addSubview:_timeLabel];
        
        _placeLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 60, SCREEN_WIDTH - 60, 20)];
        _placeLabel.textColor = [UIColor whiteColor];
        _placeLabel.font = [UIFont systemFontOfSize:15];
        [_bgImageView addSubview:_placeLabel];
        
        _author = [[HTILView alloc] initWithFrame:CGRectMake(20, 170, SCREEN_WIDTH - 60, 40)];
        _author.label.textColor = [UIColor whiteColor];
        _author.imageView.layer.cornerRadius = 20;
        _author.label.font = [UIFont systemFontOfSize:15];
        [_bgImageView addSubview:_author];
        
        
    }
    
    return self;
}

- (void)setConfigureModel:(HTTravelModel *)configureModel {
    
    _configureModel = configureModel;
    [_bgImageView sd_setImageWithURL:[NSURL URLWithString:configureModel.cover_image]];
    _titleLabel.text = configureModel.name;
    _placeLabel.text = configureModel.popular_place_str;
    [_author.imageView sd_setImageWithURL:[NSURL URLWithString:configureModel.avatar_l]];
    _author.label.text = [@"by" stringByAppendingFormat:@" %@",configureModel.user_name];
    
//    CGRect bounds1 = [configureModel.name boundingRectWithSize:CGSizeMake(0, 30) options:NSStringDrawingUsesLineFragmentOrigin attributes:[NSDictionary dictionaryWithObject:[UIFont systemFontOfSize:20] forKey:NSFontAttributeName] context:nil];
//    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(20, 20, bounds1.size.width, 30)];
//    //        view.backgroundColor = [UIColor whiteColor];
//    
//    CAGradientLayer *gradientLayer = [CAGradientLayer layer];  // 设置渐变效果
//    gradientLayer.bounds = view.bounds;
//    gradientLayer.borderWidth = 0;
//    
//    gradientLayer.frame = view.bounds;
//    gradientLayer.colors = [NSArray arrayWithObjects:
//                            (id)[[UIColor blackColor] CGColor],
//                            (id)[[UIColor clearColor]CGColor], nil];
//    gradientLayer.startPoint = CGPointMake(0, 0);
//    gradientLayer.endPoint = CGPointMake(1.0, 1.0);
//    
//    [view.layer insertSublayer:gradientLayer atIndex:0];
//    [_bgImageView addSubview:view];
//    [view addSubview:_titleLabel];
//    
//    CGRect bounds2 = [configureModel.popular_place_str boundingRectWithSize:CGSizeMake(0, 20) options:NSStringDrawingUsesLineFragmentOrigin attributes:[NSDictionary dictionaryWithObject:[UIFont systemFontOfSize:15] forKey:NSFontAttributeName] context:nil];
//    
//    UIView *view1 = [[UIView alloc] initWithFrame:CGRectMake(20, 60, bounds2.size.width, 20)];
//    //        view.backgroundColor = [UIColor whiteColor];
//    
//    CAGradientLayer *gradientLayer1 = [CAGradientLayer layer];  // 设置渐变效果
//    gradientLayer1.bounds = view1.bounds;
//    gradientLayer1.borderWidth = 0;
//    
//    gradientLayer1.frame = view1.bounds;
//    gradientLayer1.colors = [NSArray arrayWithObjects:
//                             (id)[[UIColor blackColor] CGColor],
//                             (id)[[UIColor clearColor]CGColor], nil];
//    gradientLayer1.startPoint = CGPointMake(0, 0);
//    gradientLayer1.endPoint = CGPointMake(1.0, 1.0);
//    
//    [view1.layer insertSublayer:gradientLayer1 atIndex:0];
//    [_bgImageView addSubview:view1];
//    [view1 addSubview:_placeLabel];
}



- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
